﻿Public Class FrmWaterBill
    Public FOpenType As String
    Private FPInfo As BServer.FBillPrintCFG
    Private FBInfo As BServer.FBillWater
    Public FBid As String
    Private Sub FrmWaterBill_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SControl._Base_GetBillPrintConfig(UInfo.FSession, "Property", FPInfo, "")
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        Select Case FOpenType
            Case "NewBill"
                NewBill()
                FPrintBox.Enabled = False
            Case "View"
                '--取单据信息
                If FBid Is Nothing Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If CInt(FBid) <= 0 Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If GetBill() = False Then
                    MsgBox("读取单据信息失败!")
                    Dispose()
                    Return
                End If
                '-预留
                If FBInfo.FVid = Nothing Then
                    '-没审核
                    FSaveBox.Text = "收费"
                    FSaveBox.Image = My.Resources.money
                    FPrintBox.Enabled = False
                ElseIf FBInfo.FVid = UInfo.id Then
                    FSaveBox.Enabled = False
                    FPrintBox.Enabled = True
                Else
                    '--其它人的单据
                    FSaveBox.Enabled = False
                    FPrintBox.Enabled = False
                End If
            Case Else
                MsgBox("参数错误")
                Dispose()
                Return
        End Select
    End Sub

    Private Sub ButtonX5_Click(sender As Object, e As EventArgs) Handles FPageSetBox.Click
        '--读取参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        '--显示页面设置窗口
        PageSetupDialog1.ShowDialog()
        '--保存参数
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        '---------参数赋值
        FPInfo.FMarginB = ps.Margins.Bottom
        FPInfo.FMarginT = ps.Margins.Top
        FPInfo.FMarginR = ps.Margins.Right
        FPInfo.FMarginL = ps.Margins.Left
        If ps.Landscape = False Then
            FPInfo.FPaperDirect = "V"
        Else
            FPInfo.FPaperDirect = "H"
        End If
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Water", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
    End Sub

    Private Sub ButtonX4_Click(sender As Object, e As EventArgs) Handles FPrintBox.Click
        '--读取打印参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        PrintDialog1.PrinterSettings = ps.PrinterSettings
        '--弹出打印设置窗口
        If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
            Return
        End If
        '--更新打印参数
        PrintDialog1.AllowPrintToFile = False
        ps.PrinterSettings = PrintDialog1.PrinterSettings
        '--保存打印参数
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Water", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        '--增加打印次数
        If SControl._Bill_water_AddPrintCount(UInfo.FSession, FBInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        Label1.Text = "打印次数:" & FBInfo.FPCount
        '---显示预览
        PrintDocument1.DefaultPageSettings = ps
        PrintDocument1.DocumentName = "代收水费收款收据"
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
        '--增加打印次数
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        '--打印设置
        '--A4纸
        PrintDocument1.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize With {.PaperName = "A4", .Height = 1169, .Width = 827}
        '--页面设置
        PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
        '--打印机设置
        PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
        '--定义变量
        Dim g As Graphics = e.Graphics
        Dim FX As Integer = FPInfo.FMarginL
        Dim FY As Integer = FPInfo.FMarginR
        Dim fnt As Font = New Font("宋体", 20)
        Dim rect As Rectangle = Nothing

        '--绘制表格
        '-标题下两条线
        g.PageUnit = GraphicsUnit.Display
        g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(63 + FX), FControl.CalcInch(8 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(8 + FY))
        g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(63 + FX), FControl.CalcInch(9.2 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(9.2 + FY))
        '-主单据框
        rect = New Rectangle(New Point(FControl.CalcInch(22 + FX), FControl.CalcInch(29 + FY)), New Size(FControl.CalcInch(157), FControl.CalcInch(46)))
        g.DrawRectangle(Pens.Black, rect)
        '-横线
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(35 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(42 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(48 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(48 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(55 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(56 + FX), FControl.CalcInch(61 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(61 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(69 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(69 + FY))
        '-竖线
        g.DrawLine(Pens.Black, FControl.CalcInch(56 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(56 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(94 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(94 + FX), FControl.CalcInch(69 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(113 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(113 + FX), FControl.CalcInch(61 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(139 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(139 + FX), FControl.CalcInch(61 + FY))
        '---表头
        g.PageUnit = GraphicsUnit.Millimeter
        fnt = New Font("宋体", 20)
        '--标题
        g.DrawString(FCaptionLabel.Text, fnt, Brushes.Black, 73 + FX, 0 + FY)
        '--日期
        fnt = New Font("宋体", 12)
        g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, 80 + FX, 12 + FY)
        '--表头信息
        g.DrawString("交款单位: " & FNameBox.Text, fnt, Brushes.Black, 22 + FX, 16 + FY)
        g.DrawString("交 款 人: " & FCNameBox.Text, fnt, Brushes.Black, 22 + FX, 23 + FY)
        g.DrawString("编  号: " & FBillNoBox.Text, fnt, Brushes.Black, 118 + FX, 16 + FY)
        g.DrawString("验证码: " & FVerifyBox.Text, fnt, Brushes.Black, 118 + FX, 23 + FY)
        '--表尾信息
        g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 23 + FX, 77 + FY)
        '--右侧信息
        g.DrawString("①", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 38 + FY})
        g.DrawString("记", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 44 + FY})
        g.DrawString("账", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 49 + FY})
        g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 54 + FY})
        '--表格字段
        '-第一行
        g.DrawString("上次抄表数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 30 + FY})
        g.DrawString(FLRateBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 30 + FY})
        g.DrawString("使用水量", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 30 + FY})
        g.DrawString(CDbl(FQtyBox.Text).ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 30 + FY})
        '-第二行
        g.DrawString("本次抄表数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 36 + FY})
        g.DrawString(FRateBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 36 + FY})
        g.DrawString("单价", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 36 + FY})
        g.DrawString(FPriceBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 36 + FY})
        '-第三行
        g.DrawString("上次交款金额", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 43 + FY})
        g.DrawString(FLBalanceBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 43 + FY})
        g.DrawString("消费金额", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 43 + FY})
        g.DrawString(FAccBox.Text, fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 43 + FY})
        '-第四行
        g.DrawString("上次交款余额", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 49 + FY})
        g.DrawString(FCostBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 49 + FY})
        g.DrawString("管理费", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 49 + FY})
        g.DrawString(FManageFee.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 49 + FY})
        '-第五行
        g.DrawString("本次交款金额", fnt, Brushes.Black, New PointF With {.X = 26 + FX, .Y = 59 + FY})
        g.DrawString("人民币小写", fnt, Brushes.Black, New PointF With {.X = 63 + FX, .Y = 56 + FY})
        g.DrawString(FAmountBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 96 + FX, .Y = 56 + FY})
        g.DrawString("其它", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 56 + FY})
        g.DrawString(FOtherBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 56 + FY})
        '-第六行
        g.DrawString("人民币大写", fnt, Brushes.Black, New PointF With {.X = 63 + FX, .Y = 63 + FY})
        g.DrawString(FAmountBigLabel.Text, fnt, Brushes.Black, New PointF With {.X = 96 + FX, .Y = 63 + FY})
        '-第七行
        g.DrawString("参考表示数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 70 + FY})
        g.DrawString(FRefBox.Text, fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 70 + FY})
        '-----------第一段结束----------------------------

        FY += 90

        '--绘制表格
        '-标题下两条线
        g.PageUnit = GraphicsUnit.Display
        g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(63 + FX), FControl.CalcInch(8 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(8 + FY))
        g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(63 + FX), FControl.CalcInch(9.2 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(9.2 + FY))
        '-主单据框
        rect = New Rectangle(New Point(FControl.CalcInch(22 + FX), FControl.CalcInch(29 + FY)), New Size(FControl.CalcInch(157), FControl.CalcInch(46)))
        g.DrawRectangle(Pens.Black, rect)
        '-横线
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(35 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(42 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(48 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(48 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(55 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(56 + FX), FControl.CalcInch(61 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(61 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(69 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(69 + FY))
        '-竖线
        g.DrawLine(Pens.Black, FControl.CalcInch(56 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(56 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(94 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(94 + FX), FControl.CalcInch(69 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(113 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(113 + FX), FControl.CalcInch(61 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(139 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(139 + FX), FControl.CalcInch(61 + FY))
        '---表头
        g.PageUnit = GraphicsUnit.Millimeter
        fnt = New Font("宋体", 20)
        '--标题
        g.DrawString(FCaptionLabel.Text, fnt, Brushes.Black, 73 + FX, 0 + FY)
        '--日期
        fnt = New Font("宋体", 12)
        g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, 80 + FX, 12 + FY)
        '--表头信息
        g.DrawString("交款单位: " & FNameBox.Text, fnt, Brushes.Black, 22 + FX, 16 + FY)
        g.DrawString("交 款 人: " & FCNameBox.Text, fnt, Brushes.Black, 22 + FX, 23 + FY)
        g.DrawString("编  号: " & FBillNoBox.Text, fnt, Brushes.Black, 118 + FX, 16 + FY)
        g.DrawString("验证码: " & FVerifyBox.Text, fnt, Brushes.Black, 118 + FX, 23 + FY)
        '--表尾信息
        g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 23 + FX, 77 + FY)
        '--右侧信息
        g.DrawString("②", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 38 + FY})
        g.DrawString("客", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 44 + FY})
        g.DrawString("户", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 49 + FY})
        g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 54 + FY})
        '--表格字段
        '-第一行
        g.DrawString("上次抄表数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 30 + FY})
        g.DrawString(FLRateBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 30 + FY})
        g.DrawString("使用水量", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 30 + FY})
        g.DrawString(CDbl(FQtyBox.Text).ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 30 + FY})
        '-第二行
        g.DrawString("本次抄表数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 36 + FY})
        g.DrawString(FRateBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 36 + FY})
        g.DrawString("单价", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 36 + FY})
        g.DrawString(FPriceBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 36 + FY})
        '-第三行
        g.DrawString("上次交款金额", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 43 + FY})
        g.DrawString(FLBalanceBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 43 + FY})
        g.DrawString("消费金额", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 43 + FY})
        g.DrawString(FAccBox.Text, fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 43 + FY})
        '-第四行
        g.DrawString("上次交款余额", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 49 + FY})
        g.DrawString(FCostBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 49 + FY})
        g.DrawString("管理费", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 49 + FY})
        g.DrawString(FManageFee.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 49 + FY})
        '-第五行
        g.DrawString("本次交款金额", fnt, Brushes.Black, New PointF With {.X = 26 + FX, .Y = 59 + FY})
        g.DrawString("人民币小写", fnt, Brushes.Black, New PointF With {.X = 63 + FX, .Y = 56 + FY})
        g.DrawString(FAmountBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 96 + FX, .Y = 56 + FY})
        g.DrawString("其它", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 56 + FY})
        g.DrawString(FOtherBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 56 + FY})
        '-第六行
        g.DrawString("人民币大写", fnt, Brushes.Black, New PointF With {.X = 63 + FX, .Y = 63 + FY})
        g.DrawString(FAmountBigLabel.Text, fnt, Brushes.Black, New PointF With {.X = 96 + FX, .Y = 63 + FY})
        '-第七行
        g.DrawString("参考表示数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 70 + FY})
        g.DrawString(FRefBox.Text, fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 70 + FY})

        '-------------第二段结束-----------------------------
        FY += 90

        '--绘制表格
        '-标题下两条线
        g.PageUnit = GraphicsUnit.Display
        g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(63 + FX), FControl.CalcInch(8 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(8 + FY))
        g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(63 + FX), FControl.CalcInch(9.2 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(9.2 + FY))
        '-主单据框
        rect = New Rectangle(New Point(FControl.CalcInch(22 + FX), FControl.CalcInch(29 + FY)), New Size(FControl.CalcInch(157), FControl.CalcInch(46)))
        g.DrawRectangle(Pens.Black, rect)
        '-横线
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(35 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(42 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(48 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(48 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(55 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(56 + FX), FControl.CalcInch(61 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(61 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(22 + FX), FControl.CalcInch(69 + FY), FControl.CalcInch(179 + FX), FControl.CalcInch(69 + FY))
        '-竖线
        g.DrawLine(Pens.Black, FControl.CalcInch(56 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(56 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(94 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(94 + FX), FControl.CalcInch(69 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(113 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(113 + FX), FControl.CalcInch(61 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(139 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(139 + FX), FControl.CalcInch(61 + FY))
        '---表头
        g.PageUnit = GraphicsUnit.Millimeter
        fnt = New Font("宋体", 20)
        '--标题
        g.DrawString(FCaptionLabel.Text, fnt, Brushes.Black, 73 + FX, 0 + FY)
        '--日期
        fnt = New Font("宋体", 12)
        g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, 80 + FX, 12 + FY)
        '--表头信息
        g.DrawString("交款单位: " & FNameBox.Text, fnt, Brushes.Black, 22 + FX, 16 + FY)
        g.DrawString("交 款 人: " & FCNameBox.Text, fnt, Brushes.Black, 22 + FX, 23 + FY)
        g.DrawString("编  号: " & FBillNoBox.Text, fnt, Brushes.Black, 118 + FX, 16 + FY)
        g.DrawString("验证码: " & FVerifyBox.Text, fnt, Brushes.Black, 118 + FX, 23 + FY)
        '--表尾信息
        g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 23 + FX, 77 + FY)
        '--右侧信息
        g.DrawString("③", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 38 + FY})
        g.DrawString("其", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 44 + FY})
        g.DrawString("它", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 49 + FY})
        g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 182 + FX, .Y = 54 + FY})
        '--表格字段
        '-第一行
        g.DrawString("上次抄表数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 30 + FY})
        g.DrawString(FLRateBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 30 + FY})
        g.DrawString("使用水量", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 30 + FY})
        g.DrawString(CDbl(FQtyBox.Text).ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 30 + FY})
        '-第二行
        g.DrawString("本次抄表数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 36 + FY})
        g.DrawString(FRateBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 36 + FY})
        g.DrawString("单价", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 36 + FY})
        g.DrawString(FPriceBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 36 + FY})
        '-第三行
        g.DrawString("上次交款金额", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 43 + FY})
        g.DrawString(FLBalanceBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 43 + FY})
        g.DrawString("消费金额", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 43 + FY})
        g.DrawString(FAccBox.Text, fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 43 + FY})
        '-第四行
        g.DrawString("上次交款余额", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 49 + FY})
        g.DrawString(FCostBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 49 + FY})
        g.DrawString("管理费", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 49 + FY})
        g.DrawString(FManageFee.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 49 + FY})
        '-第五行
        g.DrawString("本次交款金额", fnt, Brushes.Black, New PointF With {.X = 26 + FX, .Y = 59 + FY})
        g.DrawString("人民币小写", fnt, Brushes.Black, New PointF With {.X = 63 + FX, .Y = 56 + FY})
        g.DrawString(FAmountBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 96 + FX, .Y = 56 + FY})
        g.DrawString("其它", fnt, Brushes.Black, New PointF With {.X = 114 + FX, .Y = 56 + FY})
        g.DrawString(FOtherBox.Value.ToString("0.00"), fnt, Brushes.Black, New PointF With {.X = 140 + FX, .Y = 56 + FY})
        '-第六行
        g.DrawString("人民币大写", fnt, Brushes.Black, New PointF With {.X = 63 + FX, .Y = 63 + FY})
        g.DrawString(FAmountBigLabel.Text, fnt, Brushes.Black, New PointF With {.X = 96 + FX, .Y = 63 + FY})
        '-第七行
        g.DrawString("参考表示数", fnt, Brushes.Black, New PointF With {.X = 23 + FX, .Y = 70 + FY})
        g.DrawString(FRefBox.Text, fnt, Brushes.Black, New PointF With {.X = 57 + FX, .Y = 70 + FY})
    End Sub

    Private Sub ButtonX3_Click(sender As Object, e As EventArgs) Handles FCloseBox.Click
        Dispose()
    End Sub

    Private Sub ButtonX1_Click(sender As Object, e As EventArgs)
        NewBill()
    End Sub
    Private Sub NewBill()
        GetCustList()
        FDateBox.Value = Now
        FBillNoBox.Text = String.Empty
        FVerifyBox.Text = String.Empty
        FLRateBox.Value = 0
        FRateBox.Value = 0
        FLBalanceBox.Value = 0
        FCostBox.Value = 0
        FAmountBox.Value = 0
        FAmountBigLabel.Text = "零元"
        FQtyBox.Text = String.Empty
        FPriceBox.Value = 0
        FAccBox.Text = String.Empty
        FManageFee.Value = 0
        FOtherBox.Value = 0
        FRefBox.Text = 0
        FMakerBox.Text = UInfo.FRName
        FVermanBox.Text = Nothing
        FBInfo = New BServer.FBillWater
        CHGCntls(True)
    End Sub
    Private Sub CHGCntls(ByVal FStat As Boolean)
        FLRateBox.Enabled = FStat
        FRateBox.Enabled = FStat
        FLBalanceBox.Enabled = FStat
        FCostBox.Enabled = FStat
        FAmountBox.Enabled = FStat
        FPriceBox.Enabled = FStat
        FManageFee.Enabled = FStat
        FOtherBox.Enabled = FStat
    End Sub
#Region "取客户列表"
    Private Sub GetCustList()
        Dim ErrString As String = String.Empty
        Dim ds As New DataSet
        Dim TmpArr As Byte() = Nothing
        If SControl._BILL_Water_GetCustomList(UInfo.FSession, "*", TmpArr, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        FControl.DsRestore(ds, TmpArr)
        FNameBox.DataSource = ds.Tables(0).DefaultView
        FCNameBox.DataSource = ds.Tables(0).Copy.DefaultView
        FNameBox.ValueMember = "id"
        FNameBox.DisplayMember = "FName"
        FCNameBox.ValueMember = "id"
        FCNameBox.DisplayMember = "FCName"
        FNameBox.SelectedIndex = -1
        FCNameBox.SelectedIndex = -1
        IsOver = True
    End Sub
#End Region
    Private IsOver As Boolean = False
    Private Sub FNameBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FNameBox.SelectedIndexChanged
        If FOpenType = "View" Then
            Return
        End If
        If FNameBox.SelectedIndex >= 0 Then
            FCNameBox.SelectedIndex = FNameBox.SelectedIndex
        End If
        '--取客户信息
        If FNameBox.SelectedIndex < 0 Then
            Return
        End If
        If IsOver = False Then
            Return
        End If
        Try
            Dim FCinf As New BServer.FBaseWater With {.id = FNameBox.SelectedValue}
            Dim ErrString As String = String.Empty
            If SControl._BILL_Water_GetCustInfo(UInfo.FSession, FCinf, ErrString) = False Then
                Return
            End If
            If FBInfo Is Nothing Then
                FBInfo = New BServer.FBillWater
            End If
            FBInfo.FCustom = FCinf
            FLRateBox.Value = FCinf.FRate
            FLBalanceBox.Value = FCinf.FBalance
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FNameBox_TextChanged(sender As Object, e As EventArgs) Handles FNameBox.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim s As Integer = FNameBox.FindStringExact(FNameBox.Text)
            If s >= 0 Then
                If FNameBox.SelectedIndex <> s Then
                    FNameBox.SelectedIndex = s
                End If
            End If
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FLRateBox_ValueChanged(sender As Object, e As EventArgs) Handles FLRateBox.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--使用水量
            FQtyBox.Text = FRateBox.Value - FLRateBox.Value
           
        Catch ex As Exception

        End Try
        Try
            '--参考表示数
            FRefBox.Text = (FAmountBox.Value + FCostBox.Value) / FPriceBox.Value + FRateBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FRateBox_ValueChanged(sender As Object, e As EventArgs) Handles FRateBox.ValueChanged
        If FOpenType = "View" Then
            Return
        End If

        Try
            '--参考表示数
            FRefBox.Text = (FAmountBox.Value + FCostBox.Value) / FPriceBox.Value + FRateBox.Value
        Catch ex As Exception

        End Try
        Try
            '--使用水量
            FQtyBox.Text = FRateBox.Value - FLRateBox.Value
        Catch ex As Exception

        End Try

    End Sub

    Private Sub FLBalanceBox_ValueChanged(sender As Object, e As EventArgs) Handles FLBalanceBox.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--参考表示数
            FRefBox.Text = (FAmountBox.Value + FCostBox.Value) / FPriceBox.Value + FRateBox.Value

        Catch ex As Exception

        End Try
        Try
            '--上次余额
            FCostBox.Value = FLBalanceBox.Value - CDbl(FAccBox.Text) - FManageFee.Value - FOtherBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FCostBox_ValueChanged(sender As Object, e As EventArgs) Handles FCostBox.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--参考表示数
            FRefBox.Text = (FAmountBox.Value + FCostBox.Value) / FPriceBox.Value + FRateBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FAccBox_TextChanged(sender As Object, e As EventArgs) Handles FAccBox.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--上次余额
            FCostBox.Value = FLBalanceBox.Value - CDbl(FAccBox.Text) - FManageFee.Value - FOtherBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FManageFee_ValueChanged(sender As Object, e As EventArgs) Handles FManageFee.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--上次余额
            FCostBox.Value = FLBalanceBox.Value - CDbl(FAccBox.Text) - FManageFee.Value - FOtherBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FOtherBox_ValueChanged(sender As Object, e As EventArgs) Handles FOtherBox.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--上次余额
            FCostBox.Value = FLBalanceBox.Value - CDbl(FAccBox.Text) - FManageFee.Value - FOtherBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FQtyBox_TextChanged(sender As Object, e As EventArgs) Handles FQtyBox.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--消费金额
            FAccBox.Text = CDbl(FQtyBox.Text) * FPriceBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FPriceBox_ValueChanged(sender As Object, e As EventArgs) Handles FPriceBox.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--参考表示数
            FRefBox.Text = (FAmountBox.Value + FCostBox.Value) / FPriceBox.Value + FRateBox.Value
        Catch ex As Exception

        End Try
        Try
            '--消费金额
            FAccBox.Text = CDbl(FQtyBox.Text) * FPriceBox.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FAmountBox_ValueChanged(sender As Object, e As EventArgs) Handles FAmountBox.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            '--参考表示数
            FRefBox.Text = (FAmountBox.Value + FCostBox.Value) / FPriceBox.Value + FRateBox.Value
        Catch ex As Exception

        End Try
        Try
            FAmountBigLabel.Text = FControl.MoneyToUpper(FAmountBox.Value)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ButtonX2_Click(sender As Object, e As EventArgs) Handles FSaveBox.Click
        Try

            Dim errstring As String = String.Empty
            If FBInfo.id = 0 Then
                '--新单
                If FNameBox.Text = String.Empty Then
                    MsgBox("客户名必填")
                    Return
                End If
                If FRateBox.Value = 0 Then
                    MsgBox("抄表数必填")
                    Return
                End If
                If FAmountBox.Value = 0 Then
                    MsgBox("交款数必填!")
                    Return
                End If
                '--组合
                FBInfo = New BServer.FBillWater
                FBInfo.FCustom = New BServer.FBaseWater
                '--客户
                If FNameBox.FindStringExact(FNameBox.Text) <> FNameBox.SelectedIndex Or FNameBox.SelectedIndex = -1 Then
                    FBInfo.FCustom.id = -1
                Else
                    FBInfo.FCustom.id = FNameBox.SelectedValue
                End If
                FBInfo.FCustom.FName = FNameBox.Text
                FBInfo.FCustom.FCName = FCNameBox.Text
                FBInfo.FCustom.FRate = FRateBox.Value
                FBInfo.FCustom.FUse = FQtyBox.Text
                FBInfo.FCustom.FBalance = FAmountBox.Value + FCostBox.Value
                FBInfo.FLRate = FLRateBox.Value
                FBInfo.FRate = FRateBox.Value
                FBInfo.FCost = FCostBox.Value
                FBInfo.FLBalance = FLBalanceBox.Value
                FBInfo.FAmount = FAmountBox.Value
                FBInfo.FQty = FQtyBox.Text
                FBInfo.FPrice = FPriceBox.Value
                FBInfo.FAcc = FAccBox.Text
                FBInfo.FManageFee = FManageFee.Value
                FBInfo.FOther = FOtherBox.Value
                FBInfo.FRef = FRefBox.Text
                FBInfo.FDate = FDateBox.Value
                If SControl._BILL_Water_SaveBill(UInfo.FSession, FBInfo, errstring) = False Then
                    MsgBox(errstring)
                    FBInfo = Nothing
                    Return
                End If
                '--单号验证码
                FBillNoBox.Text = FBInfo.FBillNo
                FVerifyBox.Text = FBInfo.FVerifyCode
                CHGCntls(False)
                FSaveBox.Image = My.Resources.money
                FSaveBox.Text = "收费"
            ElseIf FBInfo.FVid = Nothing And FBInfo.id > 0 Then
                '--审核 
                If SControl._BILL_Water_SaveBill(UInfo.FSession, FBInfo, errstring) = False Then
                    MsgBox(errstring)
                    Return
                End If
                '--审核成功
                FVermanBox.Text = FBInfo.FVName
                FPrintBox.Enabled = True
                MsgBox("收费成功!")
                FSaveBox.Enabled = False
                FNameBox.Enabled = False
                FCNameBox.Enabled = False
            Else
                MsgBox("参数错误!")
                Return
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            FBInfo = Nothing
        End Try
    End Sub
#Region "取单据信息"
    Private Function GetBill() As Boolean
        Try
            FBInfo = New BServer.FBillWater() With {.id = FBid}
            Dim ErrString As String = String.Empty
            If SControl._BILL_Water_GetBillInfo(UInfo.FSession, FBInfo, ErrString) = False Then
                MsgBox(ErrString)
                Return False
            End If
            CHGCntls(False)
            FDateBox.Value = FBInfo.FDate
            FNameBox.Text = FBInfo.FCustom.FName
            FCNameBox.Text = FBInfo.FCustom.FCName
            FBillNoBox.Text = FBInfo.FBillNo
            FVerifyBox.Text = FBInfo.FVerifyCode
            FLRateBox.Value = FBInfo.FLRate
            FRateBox.Value = FBInfo.FRate
            FLBalanceBox.Value = FBInfo.FLBalance
            FCostBox.Value = FBInfo.FCost
            FAmountBox.Value = FBInfo.FAmount
            FAmountBigLabel.Text = FControl.MoneyToUpper(FAmountBox.Value)
            FQtyBox.Text = FBInfo.FQty
            FPriceBox.Value = FBInfo.FPrice
            FAccBox.Text = FBInfo.FAcc
            FManageFee.Value = FBInfo.FManageFee
            FOtherBox.Value = FBInfo.FOther
            FMakerBox.Text = FBInfo.FUName
            FVermanBox.Text = FBInfo.FVName
            FRefBox.Text = FBInfo.FRef
            Label1.Text = "打印次数:" & FBInfo.FPCount
            FNameBox.Enabled = False
            FCNameBox.Enabled = False
            FDateBox.Enabled = False
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
#End Region

End Class